<template>
    <div>
        <ul class="health-box clearfix b-g-f">
            <li class="clearfix health-box-li">
                <span class="health-box-li-span">
                    患者姓名
                </span>
                <input type="text" v-model="record.name" class="health-box-li-input" placeholder="请填写姓名" :disabled="isdisabled" />
                <div class="health-bianji" v-if="isRecord" @click="bianji()">
                    <img class="health-bianji-img" src="../../../static/img/bianji.png" alt="">
                    编辑
                </div>
            </li>
            <li class="clearfix health-box-li">
                <span class="health-box-li-span">
                    联系电话
                </span>
                <input type="text" v-model="record.tel" class="health-box-li-input" placeholder="请填写联系电话" :disabled="isdisabled" />
            </li>
            <li class="clearfix health-box-li">
                <span class="health-box-li-span">
                    主管医师
                </span>
                <input type="text" v-model="record.doctor" class="health-box-li-input" placeholder="请填写医师姓名" :disabled="isdisabled" />
            </li>
            <li class="clearfix health-box-li health-textarea-box">
                <span class="health-box-li-span">
                    随访要点
                </span>
                <textarea class="health-box-li-textarea" v-model="record.follow_points" placeholder="请填写随访注意事项" :disabled="isdisabled"></textarea>
            </li>
            <li class="clearfix health-box-li health-textarea-box">
                <span class="health-box-li-span">
                    随访记录
                </span>
                <textarea class="health-box-li-textarea" v-model="record.follow_records" placeholder="请填写随访记录" :disabled="isdisabled"></textarea>
            </li>
        </ul>
        <ul class="health-box clearfix b-g-f" v-if="dietitian == 'follow' && record.dietitian_remark">
            <li class="clearfix health-box-li health-textarea-box">
                <span class="health-box-li-span">
                    营养师备注
                </span>
                <textarea class="health-box-li-textarea" v-model="record.dietitian_remark" placeholder="请填写随访记录" :disabled="isdietitian"></textarea>
            </li>
        </ul>
        <div class="add-address" v-if="isSuccess" @click="isAdd()">
            完成
        </div>
    </div>
</template>
<script>
import { Toast } from 'vant'
export default {
    data(){
        return{
            record: {},
            isdisabled:true,
            dietitian:this.$route.query.dietitian,
            isRecord:false,
            isdietitian:false,
            isSuccess:false,
            
        }
    },
    mounted(){
        if(this.dietitian == 'dietitian'){
            this.record = eval('(' + this.$route.query.record + ')')
            if(this.record.dietitian_remark){
                this.isRecord = true
                this.isdietitian = true
            }else{
                this.isSuccess = true
            }
        }else{
            if(this.$route.query.record){
                this.record = eval('(' + this.$route.query.record + ')')
                this.isRecord = true
                this.isdietitian = true
            }else{
                this.isSuccess = true
                this.isdisabled = false
                this.record.health_records_id = this.$route.query.healthId
                this.record.uid = this.$route.query.id
            }
        }
    },
    methods:{
        // 添加判断
        isAdd(){
            if(this.dietitian == 'dietitian'){
                this.setDietitianRemark()
            }else{
                if(this.$route.query.record){
                    this.record.id = this.record.id
                }
                this.addFollowRecords()
            }
        },
        // 添加营养师备注
        setDietitianRemark(){
            this.$api.dietitian.setDietitianRemark({id:this.record.id,dietitian_remark:this.record.dietitian_remark}).then(resp=>{
                if(resp.code == 1){
                    Toast('添加成功')
                    this.$router.go(-1)
                }
            })
        },
        // 添加随访记录
        addFollowRecords(){
            this.$api.follow.addFollowRecords(this.record).then(resp=>{
                if(resp.code == 1){
                    Toast('添加成功')
                    this.$router.go(-1)
                }else{
                    Toast(resp.msg)
                }
            })
        },
        // 编辑
        bianji(){
            if(this.dietitian == 'dietitian'){
                this.isdietitian = false
                this.isSuccess = true
                this.isRecord = false
            }else{
                this.isdietitian = true
                this.isdisabled = false
                this.isSuccess = true
                this.isRecord = false
            }
        }
    }
}
</script>

